// index.js
import api from '../../utils/api'
import {
  showStatus
} from '../../utils/util'
Page({
  data: {
    dataList: [],
    searchForm: {
      createTime: '',
      pageNum: 1,
      pageSize: -1
    },
    formList: []
  },
  async onLoad() {
    this.getList()
    this.searchList()
  },
  async searchList() {
    let arr = [],
      arr2 = []
    await api.getDictData({
      dictCode: 'SYGL/SPZT'
    }).then(res => {
      res.data.forEach(item => {
        arr.push({
          name: item.dictName,
          value: item.dictValue
        })
      });
    })
    await api.getDictData({
      dictCode: 'SYGL/FKLX'
    }).then(res => {
      res.data.forEach(item => {
        arr2.push({
          name: item.dictName,
          value: item.dictValue
        })
      });
    })
    let formList = [{
        name: '申请状态',
        key: 'appStatus',
        value: '',
        label: '',
        type: 'picker',
        list: arr
      },
      {
        name: '访客类型',
        key: 'field2',
        value: '',
        label: '',
        type: 'picker',
        list: arr2
      }
    ]
    this.setData({
      formList: formList
    });
  },
  async getList() {
    const data = await api.applyBatchWeChatList(
      this.data.searchForm
    )
    const dataLIST = data.data.records
    showStatus(dataLIST, {
      value: 'appStatus',
      type: 'SYGL/SPZT'
    }).then(res => {
      this.setData({
        dataList: res,
      });
    })
    showStatus(dataLIST, {
      value: 'field2',
      type: 'SYGL/FKLX'
    }).then(res => {
      this.setData({
        dataList: res,
      });
    })
  },
  //访客申报
  showAdd() {
    wx.navigateTo({
      url: '/pages/visitorAdd/visitor', //附带两个参数过去
    })
  },
  bindchange: function (e) {
    console.log(e.detail)
  },
  delList() {
    console.log(this.data.dataList)
  },
  searchChangeL(e) {
    this.data.searchForm = Object.assign({}, this.data.searchForm, e.detail);
    this.getList()
  },
  searchInput: function (e) {
    let searchForm = {
      createTime: e.detail.value,
      pageNum: 1,
      pageSize: -1
    }
    this.setData({
      searchForm: searchForm
    })
    this.getList()
  },
  showDetail: function (e) {

    const id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '/pages/visitorDetail/visitor?id=' + id, //附带两个参数过去
    })
  },
})